2025-05-29

Custom Emacs qalc REPL Pop-Up

I like to use qalc for calculating things. I know emacs has both calc and quick-calc, but I am very used to qalc, more specifically it's CLI version.

I mostly stick to qalc because it understands (custom) units. I am currently working with a binary fileformat which has multiple odd ways to count time. Qalc is very helpful here:

> 1.5625ns to 260.41666ps

  1.5625 nanoseconds ≈ 6.000000154 × 260.41666 ps

I could get that number without qalc, but it gets me there just a tiny bit more comfortably.

So for a long time now I've always just opened a terminal running qalc next to emacs. It only recently occured to me that I can run qalc inside emacs!

So first, here is a function which wraps any programm that presents a REPL in an emacs buffer plus window. We are using normal shell mode, so we only have to worry about wrangling buffers.

(defun lhp/replify (cmd bname)
  (if (string= bname (buffer-name))
    (quit-window)
  (pop-to-buffer
   (or (get-buffer bname)
         (window-buffer
          (async-shell-command cmd bname))))))

(defun qalc ()
  "Open a qalc REPL"
  (interactive)
  (lhp/replify "qalc" "*qalc*"))

A REPL function using this helper function will try to focus the window displaying the REPL buffer, optionally creating the buffer, launching the program and creating the window. Is the buffer already focused, instead close the window.

As you can probably tell, I really like dwim – "Do what I mean" – commands in emacs. Functions which can do one of multiple different actions, based on a usually reasonable, heuristics based guess.

Arguably closing the window is a more opinionated choice than hiding the buffer. But it makes sense if I show you the second half of this:

(setq display-buffer-alist
        '(;; ...

          ("\*qalc\*"
           (display-buffer-reuse-mode-window
            display-buffer-in-side-window)
           (dedicated . t)
           (inhibit-switch-frame . t)
           (side . bottom))

          ;; ...
          ))

Using an entry in display-buffer-alist, I told emacs to open my special *qalc* REPL buffer in a dedicated side-window at the bottom of the frame. Combined with a keybind for the qalc function (I use C-c q), I have a very quick and convenient way of showing and hiding a popup with a qalc REPL.

I literally have to think about nothing: Press C-c q once to open the REPL. Press again to hide it. My window layout remains undisturbed thanks to using a side-window and emacs takes care of spawning the program if it is not already running. And since the window is closed but the buffer isn't killed, the REPL session will stay alive; Basically like a little math scratchpad.

Side-windows are the best way I have found to make emacs window management pleasant. Everything that comes and goes often and isn't the main buffer required for a task should probably be a side-window. For me that mostly means my qalc REPL (bottom), compilation (bottom) and rgrep plus occur (right).

tub.webp

Warm air and buzzing insects surround me. The kind of day were you can actually work outside. The kind of work that feels good but isn't too productive. The kind of productivity that is more fun than ultimately useful.

Why bring the kitchen sink if you can bring a bath tub?

I decided to share this as a blog post because I think chances are high someone else will find this useful as well. I hope your day is as lovely as mine 🐈

Articles from blogs I read (generated by openring)

Status update, November 2025

Hi! This month a lot of new features have added to the Goguma mobile IRC client. Hubert Hirtz has implemented drafts so that unsent text gets saved and network disconnections don’t disrupt users typing a message. He also enabled replying to one’s own messages…

emersion, November 16, 2025

the last couple years in v8's garbage collector

Let’s talk about memory management! Following up on my article about 5 years of developments in V8’s garbage collector, today I’d like to bring that up to date with what went down in V8’s GC over the last couple years.methodololologyI selected all of the …

wingolog, November 13, 2025

OpenAI employees… are you okay?

You might have seen an article making the rounds this week, about a young man who ended his life after ChatGPT encouraged him to do so. The chat logs are really upsetting. Someone two degrees removed from me took their life a few weeks ago. A close friend rel…

Drew DeVault's blog, November 8, 2025